﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using SpringStudio.Common;
using SpringStudio.DAL;

namespace Sdepci.InfoCode.BLL.CodeDesign
{
    /// <summary>
    /// 编码规则表
    /// </summary>
    public class TypeRule
    {
        #region 属性定义

        private string _ruleGuid;
        /// <summary>
        /// 编码规则Guid
        /// </summary>
        public string RuleGuid
        {
            get { return this._ruleGuid; }
        }

        private string _ruleName;
        /// <summary>
        /// 规则名称
        /// </summary>
        public string RuleName
        {
            get { return this._ruleName; }
        }

        private string _ruleDesc;
        /// <summary>
        /// 中文说明
        /// </summary>
        public string RuleDesc
        {
            get { return this._ruleDesc; }
        }

        private string _ruleModule;
        /// <summary>
        /// 规则模型
        /// </summary>
        public string RuleModule
        {
            get { return this._ruleModule; }
        }

        private string _ruleDemo;
        /// <summary>
        /// 编码示例
        /// </summary>
        public string RuleDemo
        {
            get { return this._ruleDemo; }
        }

        private int _seq;
        /// <summary>
        /// 显示次序
        /// </summary>
        public int Seq
        {
            get { return this._seq; }
        }

        #endregion

        #region 构造方法

        public TypeRule(string ruleGuid)
        {
            this._ruleGuid = ruleGuid;

            try
            {
                string sql = "Select RuleGuid,RuleName,RuleDesc,RuleModule,RuleDemo,Seq From InfoCodeTypeRules Where RuleGuid=@RuleGuid";
                DataSet ds = SqlHelper.ExecuteDataSet(ConnectionString.Default, CommandType.Text, sql,
                    SqlHelper.NewSqlParameter("@RuleGuid", this._ruleGuid));
                if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
                {
                    DataRow row = ds.Tables[0].Rows[0];
                    this._ruleGuid = row["RuleGuid"].ToString();
                    this._ruleName = row["RuleName"].ToString();
                    this._ruleDesc = row["RuleDesc"].ToString();
                    this._ruleModule = row["RuleModule"].ToString();
                    this._ruleDemo = row["RuleDemo"].ToString();
                    this._seq = int.Parse(row["Seq"].ToString());
                }
                else
                {
                    throw new Exception("没有找到该值对应的详细记录！（参数：ruleGuid'" + this._ruleGuid + "'）");
                }
            }
            catch (Exception ex)
            {
                ExceptionHandler.Handle(ex);
            }
        }

        #endregion
    }
}
